require File.expand_path('../config/application', __FILE__)

UnifiedPayment::Application.load_tasks

task :test_unified_payment do 
  puts 'creating symlink for spec files...'
  system 'ln -s ../../spec'

  puts 'setting up db with migration(s)'
  
  puts 'create db'
  system 'bundle exec rake db:create RAILS_ENV=test'
  
  puts 'copy migration(s)'
  require File.expand_path('../../lib/generators/unified_payment/install_generator')
  UnifiedPayment::InstallGenerator.new.create_migrations
  
  puts 'running migrations...'
  system 'bundle exec rake db:migrate RAILS_ENV=test'

  puts 'running specs...'
  system 'bundle exec rspec spec'

  puts 'dropping the db created for test...'
  system 'bundle exec rake db:drop'

  puts 'unlinking spec files...'
  system 'unlink spec'

  puts 'removing db files...'
  system 'rm -rf db'
end